home *** CD-ROM | disk | FTP | other *** search
- //***************************************************************************
- //* *
- //* Interactive 3D Tool Kit I3D v2.0 *
- //* *
- //* I3D API *
- //* *
- //* (c) 1993-94 Jim O'Keane *
- //* All Rights Reserved Worldwide *
- //* *
- //***************************************************************************
-
- #ifndef _I3DKIT_H
-
- #define _I3DKIT_H 1
-
- // Simple macros to facilitate global vars in .h files
- // Define MAIN in only one file before #includes.
- #ifndef MAIN
- #define GLOBAL extern
- #else
- #define GLOBAL
- #endif
-
- // MS Windows-like types
- #ifndef __WINDOWS_H
- typedef unsigned char BYTE;
- typedef unsigned short WORD;
- typedef unsigned long DWORD;
- typedef short BOOL;
- #define FALSE 0
- #define TRUE 1
-
- typedef struct
- {
- short x;
- short y;
- } POINT;
-
- #endif
-
-
- #ifndef FAR
- #define FAR far
- #endif
-
- #ifndef NEAR
- #define NEAR near
- #endif
-
- #ifndef PASCAL
- #define PASCAL pascal
- #endif
-
- #ifdef __FLAT__
- // If 32 bit compiler, dump the "far", "near" and the "pascal"
-
- #undef FAR
- #define FAR
-
- #undef NEAR
- #define NEAR
-
- #undef PASCAL
- #define PASCAL
-
- #endif
-
- // Maps are always 128 by 128 blocks. (128 x 128 x 2 = 32K Bytes)
- // If you need a smaller map, just don't use whole array.
- // The map contains indexes into the block definition array.
- #define MAP_WIDTH 128
- #define MAP_HEIGHT 128
-
- // Automapping flags
- #define AUTOMAP_SEEN 1 // block has been seen by the viewer (automap)
-
- // Map array type
- typedef short MAPTYPE[MAP_WIDTH][MAP_HEIGHT];
-
- // the VGA palette data structure
- typedef BYTE DACPAL256[256][3];
-
- // size of map cell 256x256x256 units (high byte of world coords is map coord)
- #define BLOCK_SIZE 256
- // mask is used to find position inside a block
- #define BLOCK_MASK 255
- // shift is used to find the map coords from world coords
- #define BLOCK_SHIFT 8
-
- // Block shape types
- #define BLOCK_OPEN 0 // block is just floor & ceiling
- #define BLOCK_CUBE 1 // block is a cube
- #define BLOCK_HORZ 2 // block is a horizontal (EW) divider
- #define BLOCK_VERT 3 // block is a vertical (NS) divider
- #define BLOCK_ACTOR 4 // block is an actor or prop
- #define BLOCK_DIAG1 5 // block is a diagonal wall
- #define BLOCK_DIAG2 6 // block is a diagonal wall
-
- // Bit flags used by I3D Engine
- #define BLOCK_TRANS 1 // block is transparent
- #define BLOCK_WALL 2 // block is an impassable
- #define BLOCK_BI 4 // Thing is bilaterally symmetric, saves views
-
- // definition of a block
- typedef struct tag_block
- {
- short shape; // type of shape
- short flags; // bit flags
-
- short light; // "light" level 0 = normal, < 0 "darker", > 0 "lighter"
-
- short twidth; // texture map width (32,64,128)
- short twidth_shift; // texture map width in shift (5,6,7)
- short theight; // texture map height
- short tsize; // texture map size in bytes
-
- short x_offset; // positional offset (+/- 1/2 BLOCK_SIZE)
- short y_offset; // used to animate blocks and things
-
- short n_wall; // wall panel to show (-1 = none)
- short e_wall; // wall panel to show (-1 = none)
- short s_wall; // wall panel to show (-1 = none)
- short w_wall; // wall panel to show (-1 = none)
-
- short ceil; // ceiling panel to show - must be (twidth x twidth)
- short floor; // floor panel to show - must be (twidth x twidth)
-
- short user1; // user defined
- short user2;
- short user3;
- short user4;
- } BLOCK;
-
- // if a block is an actor or prop, cast the block struct to this:
- typedef struct tag_thing
- {
- short shape; // type of shape
- short flags; // bit flags
-
- short light; // "light" level 0 = normal, < 0 darker, > 0 lighter
-
- short twidth; // texture map width (32,64,128)
- short twidth_shift; // texture map width in shift (5,6,7)
- short theight; // texture map height
- short tsize; // texture map size in bytes
-
- short x_offset; // positional offset +/- 1/2 BLOCK_SIZE
- short y_offset; // used to animate blocks and things
-
- short panel; // base panel to show (-1 = none)
- short block; // what background block is at this location
- short views; // how many directions give different views?
- short heading; // direction facing
-
- short res1;
- short res2;
-
- short user1; // user defined
- short user2;
- short user3;
- short user4;
- } THING;
-
- // standard image operator macros
- #define IMAGE_SIZE256(width,height) ((long)(width)*(height))
-
- // calc offset into image byte array for a pixel at (x,y)
- #define PIXPOS(x,y,width) (((y)*(width))+(x))
-
- // handy macros
- #define MIN(a,b) ((a) < (b) ? (a) : (b))
- #define MAX(a,b) ((a) > (b) ? (a) : (b))
- #define SIGN(x) (((x) < 0) ? -1 : (((x) > 0) ? 1 : 0))
- #define ABS(x) ((x)<0 ? -(x):(x))
-
- // Prototypes ////////////////////////////////////////////////////
-
- #if defined ( __cplusplus )
- extern "C" {
- #endif
-
- // Quicky integer math functions. High speed, low accuracy.
- short FAR q_sin( short angle );
- short FAR q_cos( short angle );
- // rotate point (x,y) about center (cx,cy) by angle
- void FAR rotate(short *x, short *y, short cx, short cy, short angle);
-
- // I3D functions ////////////////////////////
-
- // Tell the I3D engine what map to use. I3D keeps a copy of
- // this pointer, so you can change the map on the fly.
- // If the automap_ptr is NULL, no auto-mapping is done.
-
- BOOL FAR i3d_set_map(MAPTYPE *map_ptr,MAPTYPE *automap_ptr);
-
- // Tell the I3D engine about the texture map panels. I3D keeps a copy of
- // the pointer to the panel list, so you can change the texture maps on
- // the fly.
-
- BOOL FAR i3d_set_panels(short num_panels, BYTE **panel_list);
-
- // Tell the I3D engine about you block definition list. I3D keeps a copy
- // of the pointer to the block list, so you can change the block definitions
- // on the fly.
-
- BOOL FAR i3d_set_blocks(short num_blocks, BLOCK *block_list);
-
- // Tell the I3D engine to use a solid color for floors and ceilings. If set
- // to zero, uses texture mapped floors and/or ceilings. If set to -1, then
- // no drawing is done, caller is expected to fill POV buffer with backdrop.
-
- BOOL FAR i3d_set_floor_ceil(short floor_col, short ceil_col);
-
- // Tell the I3D engine to use a set of Palette Indirection Tables
- // I3D keeps a copy of the pointer to the paltable list, so you can change
- // the actual tables on the fly.
- //
- // max_levels is the table number which lighting effects fade to at the
- // far end. Shift is how far to right shift the distance to determine
- // the light level.
-
- // For example, I want each light level to be 1 block wide (256) so my shift
- // is 8. I set max_levels to be 16, and I can see at most 16 blocks
- // away before it is all darkness (or solid color).
-
- // Set paltables_ptr to NULL and max_levels to 0 for no lighting effects.
- // (default)
-
- void FAR i3d_set_lighting(BYTE **paltables_ptr,
- short max_levels, short shift);
-
- // Calculate the fade tables from 0% to 100% over a series of steps
-
- void FAR i3d_calc_paltables(BYTE **paltable_ptr,DACPAL256 *pal,
- short max_levels, short max_color);
-
- // Tell the I3D engine the dimensions of the window buffer it uses, and
- // the width of a line in bytes.
-
- BOOL FAR i3d_set_window_buffer(short width, short height,
- short line_width,
- BYTE *buf);
-
- // Shutdown the I3D Engine - free memory buffers
-
- void FAR i3d_shutdown(void);
-
- // Ask I3D to create a frame in the window buffer.
-
- // INPUT:
- // (s_x,s_y) = viewer eye position
- // horizon = where in POV buffer place horizon - makes head tilt up/down
- // eye_level = how high is eye? valid range 1 to (BLOCK_SIZE-1)
- // scan_width, scan_height = vary these for aspect ratio and field of view
- // (normally the same as POV window width)
- // heading = which way is viewer looking
-
- void FAR i3d_view_scan256(short s_x, short s_y,
- short horizon, short eye_level,
- long scan_width, long scan_height,
- short heading);
-
- // Ask I3D to tell you what is hit at a particular point in the window buffer.
-
- // INPUT:
- // (s_x,s_y) = viewer eye position
- // horizon = where in POV buffer place horizon - makes head tilt up/down
- // eye_level = how high is eye? valid range 1 to (BLOCK_SIZE-1)
- // scan_width, scan_height = vary these for aspect ratio and field of view
- // (normally the same as POV window width)
- // heading = which way is viewer looking
-
- // click_x,click_y = coords in POV buffer they user hit
-
- // OUTPUT:
- // h_x,h_y,h_z = position in world space point hit
- // block_id = index in block list of block hit
- // panel_u,panel_v = position in texture map hit
-
- void FAR i3d_hit_scan256(short s_x, short s_y,
- short horizon, short eye_level,
- long scan_width, long scan_height,
- short heading,
- short click_x, short click_y,
- short *h_x, short *h_y, short *h_z,
- short *block_id, short *panel_u, short *panel_v);
- #if defined ( __cplusplus )
- }
- #endif
-
- #endif
-